package com.xiaoshu.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * 功能说明： 在SpringMVC中添加拦截器，通过 Interceptor拦截器，判断请求的合法性；
 * com.xiaoshu.interceptor
 *
 * <p>
 * Original @Author: deane.jia-贾亮亮,2021/6/17 14:33
 * <p>
 * Copyright (C)2012-2021 小树盛凯科技 All rights reserved.
 */
@Configuration
public class InterceptorWebConfig implements WebMvcConfigurer {

    private ClientAuthorizationInterceptor clientAuthorizationInterceptor;

    @Autowired
    public void setClientAuthorizationInterceptor(ClientAuthorizationInterceptor clientAuthorizationInterceptor) {
        this.clientAuthorizationInterceptor = clientAuthorizationInterceptor;
    }

    /**
     * 此处添加 SpringMVC的拦截器操作
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(clientAuthorizationInterceptor);
    }

    /**
     * 针对参数进行处理/解析处理
     * @param resolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        // TODO 此处添加参数处理的 Resolver， 详细见HandlerMethodArgumentResolver处理方法
    }
}
